// 原代码

setTimeout(() => {
  var a = "hello";
  setTimeout(() => {
    var b = "lagou";
    setTimeout(() => {
      var c = "I ❤️ U";
      console.log(a + b + c);
    }, 10);
  }, 10);
}, 10);


// 改进1 (3个异步不存在结果依赖关系)
const val1 = 'hello';
const val2 = 'lagou';
const val3 = 'I ❤️ U';
const tick = (resolve, val) => setTimeout(() => { resolve(val); }, 10);

const p1 = new Promise((resolve) => { tick(resolve, val1); });
const p2 = new Promise((resolve) => { tick(resolve, val2); });
const p3 = new Promise((resolve) => { tick(resolve, val3); });
Promise.all([p1, p2, p3])
  .then((res) => { console.log(res.join("")); })
  .catch((err) => { console.error(err); });


// 改进2 （当前异步依赖上一个异步的结果）
new Promise((resolve) => { tick(resolve, val1); })
.then(res => new Promise(resolve => tick(resolve, `${res}${val2}`)))
.then(res => { console.log(`${res}${val3}`)})
.catch((err) =>  console.error(err));